package com.janko.springbootbase.designmode.multitonPattern;

import java.util.ArrayList;

public class SQLConnectionPools {

    private static int maxNumOfConnection= 8;
    private static ArrayList<String> connectionInfoList = new ArrayList<>(maxNumOfConnection);
    private static ArrayList<SQLConnectionPools> connArrayList = new ArrayList<>(maxNumOfConnection);
    private static int currNumOfConnection =0;

    private SQLConnectionPools() {

    }

    private SQLConnectionPools(String info) {
        connectionInfoList.add(info);
    }

    static{
        for (int i = 0; i < maxNumOfConnection; i++) {
            connArrayList.add(new SQLConnectionPools(i+"号连接"));
        }
    }

    public static SQLConnectionPools getInstance() {
        java.util.Random random = new java.util.Random();
        currNumOfConnection = random.nextInt(maxNumOfConnection);
        return connArrayList.get(currNumOfConnection);
    }

    public void connectionInfo() {
        System.out.println(connectionInfoList.get(currNumOfConnection));
    }

}
